//
//  YBBaseView.m
//  ChangChat
//
//  Created by Cocoa on 2019/9/26.
//  Copyright © 2019 yibai. All rights reserved.
//

#import "YBBaseView.h"

#define YBBaseView_Mask_cornerRaius 14

@implementation YBBaseView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
    }
    return self;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    
    if (self.type == 0) {    
        self.layer.mask = [self drawMaskLayer];
    }
    
}

- (CAShapeLayer *)drawMaskLayer {
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.fillColor = UIColor.k_t1Color.CGColor;
    //    maskLayer.fillColor = _msgDirection == 1 ? UIColor.k_t1Color.CGColor : UIColor.k_hexColor(0xe0e0e0).CGColor;
    maskLayer.fillColor = UIColor.redColor.CGColor;
    maskLayer.lineWidth = 0.01;
    maskLayer.lineCap = kCALineCapRound;
    maskLayer.strokeColor = UIColor.greenColor.CGColor;
    UIBezierPath *path = [UIBezierPath bezierPath];
    ///  从左下角上面开始画
    
    [path moveToPoint:CGPointMake(0, self.height)];
    
    [path addLineToPoint:CGPointMake(0, YBBaseView_Mask_cornerRaius)];
    
    [path addArcWithCenter:CGPointMake(YBBaseView_Mask_cornerRaius, YBBaseView_Mask_cornerRaius) radius:YBBaseView_Mask_cornerRaius startAngle:-M_PI endAngle:-M_PI_2 clockwise:YES];
    
    [path addLineToPoint:CGPointMake(self.width - YBBaseView_Mask_cornerRaius, 0)];
    
    [path addArcWithCenter:CGPointMake(self.width-YBBaseView_Mask_cornerRaius, YBBaseView_Mask_cornerRaius) radius:YBBaseView_Mask_cornerRaius startAngle:-M_PI_2 endAngle:0 clockwise:YES];
    
    [path addLineToPoint:CGPointMake(self.width, self.height)];
    [path addLineToPoint:CGPointMake(0, self.height)];
    
    
    
    [path closePath];
    maskLayer.path = path.CGPath;
    return maskLayer;
}


@end
